;*****************************************************
; 	Copyright (C) SEIKO EPSON CORP. 1997-2001
;	All rights Reserved
;
;	File name : strrchr.s
;	Function  :
;	       This is strrchr function
;	Revision  :
;		1997/03/25	V.Chan start
;		2001/12/06	T.Tazaki for GNU33(Linux)
;*****************************************************

;*****************************************************
; strrchr
;	finds last occurrence of char in src (0 terminated)
;
; arguments : %r6:src addr, %r7:char
; return    : %r4:located char addr
;*****************************************************

	.section .text
	.align 1
	.global strrchr
	.type	strrchr,@function

strrchr:
	ld.w	%r4, 0			; initialize as NULL
	ld.w	%r10, 1			; initialize byte

strrchr_loop:
	cmp		%r10, 0
	jreq	strrchr_ret
	ld.ub	%r10, [%r6]+		; check each byte
	cmp		%r10, %r7
	jrne	strrchr_loop

	ld.w	%r4, %r6			; addr of char
	jp.d	strrchr_loop
	sub		%r4, 1

strrchr_ret:
	ret
